import { BasicColumn, FormSchema } from "/@/components/Table"
import { render } from "/@/utils/common/renderUtils"
import { DescItem } from "/@/components/Description/index"
import { useI18n } from "/@/hooks/web/useI18n"
const { t } = useI18n("")

export const columns: BasicColumn[] = [
  {
    title: t("区域名称"),
    dataIndex: "areaName",
    width: 230,
    align: "left",
    slot: "firstColumn",
  },
  {
    title: t("区域编码"),
    dataIndex: "id",
    width: 100,
  },
  {
    title: t("排序号"),
    dataIndex: "sortNo",
    width: 130,
    align: "center",
  },
  {
    title: t("区域类型"),
    dataIndex: "areaType",
    width: 130,
    align: "center",
    customRender: ({ text }) => {
      return render.renderTag(render.renderDict(text, "sys_area_type"), "green")
    },
  },
  {
    title: t("状态"),
    dataIndex: "status",
    width: 80,
    align: "center",
    customRender: ({ text }) => {
      let color = "green"
      if (text === "0") {
        color = "red"
      }
      return render.renderTag(render.renderDict(text, "data_use_status"), color)
    },
  },
  {
    title: t("更新时间"),
    dataIndex: "updatedAt",
    width: 150,
    align: "center",
  },
  {
    title: t("备注信息"),
    dataIndex: "remark",
    width: 130,
    align: "left",
  },
]

export const searchFormSchema: FormSchema[] = [
  {
    label: t("区域名称"),
    field: "areaName",
    component: "Input",
  },
  {
    label: t("区域代码"),
    field: "areaId",
    component: "Input",
  },
  {
    label: t("状态"),
    field: "status",
    component: "JDictSelectTag",
    componentProps: {
      dictType: "data_use_status",
      placeholder: "请选择状态",
      allowClear: true,
    },
  },
]

export const inputFormSchemas: FormSchema[] = [
  {
    label: t("上级区域"),
    field: "parentId",
    component: "MyTreeSelect",
  },
  {
    label: t("区域编码"),
    field: "id",
    component: "Input",
    componentProps: {
      maxlength: 100,
    },
    rules: [{ required: true }, { pattern: /^[a-zA-Z0-9_]*$/, message: t("请输入字母数字下划线") }],
  },
  {
    label: t("区域名称"),
    field: "areaName",
    component: "Input",
    componentProps: {
      maxlength: 100,
    },
    required: true,
  },
  {
    label: t("区域类型"),
    field: "areaType",
    component: "JDictSelectTag",
    defaultValue: "1",
    componentProps: {
      type: "radio",
      dictType: "sys_area_type",
      allowClear: true,
    },
    required: true,
  },
  {
    label: t("排序号"),
    field: "sortNo",
    helpMessage: "升序",
    component: "InputNumber",
    defaultValue: "30",
    componentProps: {
      maxlength: 10,
    },
    rules: [{ required: true }, { pattern: /^\d+$/, message: t("请输入一个正整数") }],
  },
  {
    label: "状态",
    field: "status",
    required: true,
    component: "JDictSelectTag",
    defaultValue: "1",
    componentProps: {
      type: "radio",
      dictType: "data_use_status",
    },
  },
  {
    label: t("备注信息"),
    field: "remark",
    component: "InputTextArea",
    componentProps: {
      maxlength: 500,
    },
    colProps: { lg: 24, md: 24 },
  },
]
